JS_STACK_INDEX++;
JS_STACK[JS_STACK_INDEX] = 'ui_boot();';

function ui_boot() {
    load_modals();
    cancel_autoscroll_to_top();
    load_admin_interface();
    display_post_messages();
    edit_in_place_buttons();
    popup_dimensions();
    date_picker();
    delete_image_js();
    image_bank_loading();
    load_editarea();
    load_native_acordions();
    load_admin_bar();
    load_dropdown_menus();
    load_navigation();
    load_multilevel_menu();
    ajax_paginator_controls();
    load_help();
    hover_for_editable_object();
    enable_ajax_forms();
    overriden_behaviours();
    resize_edit_in_place();
}

function overriden_behaviours() {
    click($('div[type="submit"]'), function($this) {
        $this.parents('form:first').submit();
    });
}

function load_select_menus() {
    each($('.chzn-select'), function($this) {
        if (!$this.hasClass('chzn-done')) {
            $this.chosen({
                "disable_search_threshold": 10
            });
        }
    });
    if ($('.chzn-container').length) {
        $('.chzn-container').css('width', '200px');
        $('.chzn-search').css('width', '190px');
        $('.chzn-results').css('width', '190px');
    }
}

function load_multilevel_menu() {
    $('.erra-multilevel-menu').each(function() {
        $(this).menu();
    });
    $('.erra-multilevel-menu .multi-level-item').click(function() {
        var $multiLevelObject = $(this).parents('.erra-multilevel-menu').first();
        if ($(this).attr('data-value') != 'null') {
            $(this).parents('.erra-form-field-instance:first').find('input[type="hidden"]').val($(this).attr('data-value'));
            $(this).parents('.erra-form-field-instance:first').find('.erra-multilevel-label').html($(this).attr('data-label'));
            $multiLevelObject.menu("collapseAll", null, true);
        }
    });
}

function ui_boot_dynamic() {
    // Put previous data in select containers
    each($('select'), function($this) {
        $this.data('prev', $this.val());
    });
    // Those dynamic extra widgets must be loaded at runtime
    load_dynamic_tree();
    load_time_picker();
    load_color_picker();
    load_autocomplete();
    load_select_menus();
    loadWysiwyg();
    overriden_behaviours();
    resize_edit_in_place();
}

function _load_autocomplete($this, dataSource) {
    if ($this.attr('aria-autocomplete') != undefined) {
        $this.autocomplete({
            source: dataSource
        });
    } else {
        $this.autocomplete({
            source: dataSource,
            minLength: 2,
            select: function(event, ui) {
                $this.val(ui.item.label);
                $this.attr('data-value', ui.item.value);
                // Feed hidden field with real value
                var $hidden = $('#' + $this.attr('id') + '_id');
                if ($hidden.length) {
                    $hidden.focus().val(ui.item.value).trigger('change');
                }
                return false;
            }
        });
    }
}

function load_autocomplete() {
    var $jqueryAutocomplete = $(".jquery-autocomplete:not(.lazy)");
    if ($jqueryAutocomplete.length) {
        each($jqueryAutocomplete, function($this) {
            if ($this.attr('aria-autocomplete') == undefined) {
                var dataSource = $this.attr('data-source');
                $this.autocomplete({
                    source: dataSource,
                    minLength: 2,
                    select: function(event, ui) {
                        $this.val(ui.item.label);
                        $this.attr('data-value', ui.item.value);
                        // Feed hidden field with real value
                        var $hidden = $('#' + $this.attr('id') + '_id');
                        if ($hidden.length) {
                            $hidden.focus().val(ui.item.value).trigger('change');
                        }
                        return false;
                    }
                });
            }
        });
    }
}


function load_dynamic_tree() {
    var $dynamicTreeContainer = $('.dynatree-container');
    if ($dynamicTreeContainer.length) {
        each($dynamicTreeContainer, function($this) {
            // Execute only once
            if (!$this.find('.dynatree-lastsib').length) {
                var dtConfig = $.parseJSON($this.attr('data-dyna'));
                var $hidden = $('#' + $this.attr('data-content'));
                var tree = $this.dynatree({
                    debugLevel: 0,
                    checkbox: true,
                    selectMode: 3,
                    activate: true,
                    focus: true,
                    onActivate: function(node) {
                    // this is like on click
                    },
                    onSelect: function(flag, node) {
                        var selectedNodes = node.tree.getSelectedNodes();
                        var selectedKeys = $.map(selectedNodes, function(node) {
                            return node.data.key;
                        });
                        $hidden.val(selectedKeys.join("§"));
                        $hidden.change();
                    },
                    persist: false,
                    children: dtConfig
                });
            }
        });
    }
}

function load_time_picker() {
    var $timePickerInput = $('.jquery-timepicker-input');
    if ($timePickerInput.length) {
        each($timePickerInput, function($this) {
            $this.timepicker({
                hourText: 'Heure',
                minuteText: 'Minutes',
                amPmText: ['Matinée', 'Après-Midi'],
                timeSeparator: 'h',
                nowButtonText: 'Maintenant',
                showNowButton: false,
                closeButtonText: 'Fermer',
                showCloseButton: true,
                deselectButtonText: 'Désélectionner',
                showDeselectButton: false
            });
        });
    }
}

function load_color_picker() {
    var $colorPickerSelect = $('.jquery-colorpicker-select');
    if ($colorPickerSelect.length) {
        each($colorPickerSelect, function($this) {
            var on_color_change_func = $this.attr('onchange-function');
           
            $this.colourPicker({
                ico: IMAGES_FRAMEWORK + '/colourpicker/jquery.colourpicker.gif',
                title: 'Choisissez une couleur'
            });
            if(on_color_change_func != undefined){
                $('#'+$this.attr('id')).change(window[on_color_change_func]);
            }
        });
        
    }
    
}


function load_help() {
    $('.live-tipsy').tipsy({
        gravity: 's', 
        html: true 
    });
    $('.live-tipsy-s').tipsy({
        gravity: 's',
        html: true
    });
}

function load_sort_tables(selectedElement) {
    var order = selectedElement.attr('data-order');
    selectedElement.parents('div[role="dialog"]:first').find('.erra-form-common-search').each(function() {
        if ($(this).find('input[id^="order_by_"]').length) {
            $(this).find('input[id^="order_by_"]').val(selectedElement.attr('data-column-id') + '|' + order);
            $(this).submit();
        }
    });
}

function ajax_paginator_controls() {
    $('select[id*="_search_paginator_pageSize"]', '.erra-field').change(function() {
        $(this).parents('form:first').submit();
    });
    $('select[id*="_search_paginator_pageNumber"]', '.erra-field').change(function() {
        $(this).parents('form:first').submit();
    });
    // Links
    $('span[id*="search_paginator_pageNumber_link"]', '.erra-field').click(function() {
        var value = $(this).attr('rel');
        var parentForm = $(this).parents('form:first');
        parentForm.find('select[id*="_search_paginator_pageNumber"]').val(value);
        parentForm.submit();
        return false;
    });

}

function load_navigation() {
    var $sortable = $('ol.sortable');
    if ($sortable.length > 0) {
        $sortable.nestedSortable({
            disableNesting: 'no-nest',
            forcePlaceholderSize: true,
            handle: 'div',
            helper: 'clone',
            items: 'li',
            maxLevels: 3,
            opacity: .6,
            placeholder: 'placeholder',
            revert: 250,
            tabSize: 25,
            tolerance: 'pointer',
            toleranceElement: '> div'
        });
    }

    $('input[name*="erra__navigation_data"]').each(function() {
        $(this).parents('form:first').find('input[type="submit"]').click(function() {
            var serialized = $(this).parents('div[role="dialog"]:first').find('ol.sortable').nestedSortable('serialize');
            $(this).parents('form:first').find('input[name*="erra__navigation_data"]').val(serialized);

        });
    });


}
function load_admin_bar() {
    if ($("#adminBar").length > 0) {
        $("#adminBar").css('z-index', 1000);
        $("#adminBar").prependTo('body');
        if ($("#ufm__adminBar").length > 0) {
            $("#ufm__adminBar").ptMenu();
        }
    }
}

function load_dropdown_menus() {
    each($(".erra__drowpdown"), function($this) {
        $this.ptMenu();
    });
}


function get_selected_id(objectId) {
    var $selectedObjects = $('input[name^="CheckItem:' + objectId + '"]:checked');
    if ($selectedObjects.length) {
        var selectedList = '';
        each($selectedObjects, function($this) {
            selectedList = selectedList + $this.attr('name') + '|';
            $('input[name="CheckList:' + objectId + '"]').val(selectedList);
        });
    }
}

function load_native_acordions() {
    $('.erra-form-common-accordion_container').each(function() {
        var itemCount = 0;
        var $parentDiv = $(this);
        $(this).find('div[class*="multiple_field_instance"]').each(function() {
            // Start by hiding content
            var accordionElement = $(this);
            var fieldContent = $(this).find('div:first');
            if (itemCount != 0) {
                fieldContent.hide();
            }
            itemCount++;
            var currentSlide = $(this);

            // Add click callback for each title
            $(this).find('h3:first').click(function() {
                $parentDiv.find('div[class*="multiple_field_instance"]').find('div[id^="divMultipleInstance"]').each(function() {
                    if ($(this).attr('id') != currentSlide.find('div:first').attr('id')) {
                        $(this).slideUp();
                    }
                });
                fieldContent.slideDown();
            });

            // delete button
            $(this).find('a[id^="divMultipleDelete_"]').click(function() {
                accordionElement.remove();
                return false;
            });

            // Up button
            $(this).find('a[id^="divMultipleDown_"]').click(function() {
                var nextElement = accordionElement.next('div[class*="multiple_field_instance"]');
                if (nextElement.length > 0) {
                    accordionElement.insertAfter(nextElement);
                }
                return false;
            });

            // Down button
            $(this).find('a[id^="divMultipleUp_"]').click(function() {
                var prevElement = accordionElement.prev('div[class*="multiple_field_instance"]');
                if (prevElement.length > 0) {
                    accordionElement.insertBefore(prevElement);
                }
                return false;
            });
        })
    });
}

function editarea_save() {
    $('textarea[id$="editareaZone"], .editareaZone').each(function() {
        var textarea_id = $(this).attr('id');
        var form = $(this).parents('form:first');
        $(this).val(editAreaLoader.getValue(textarea_id));

        form.submit();

        // Refresh preview if exists
        if ($('#viewEditorPreview').length > 0) {
            var form = $(this).parents('form:first');
            var newFileValue = form.find('select[id$="developerChangeItem"]').val();
            var iFrameTarget = WEBROOT + '/preview/' + newFileValue;
            $('#viewEditorPreview').attr('src', iFrameTarget);
        }
    });
}

function load_editarea() {
    $('.editareaZone').each(function() {
        var textarea_id = $(this).attr('id');
        editAreaLoader.init({
            id: textarea_id,
            start_highlight: true,
            allow_resize: "both",
            allow_toggle: true,
            word_wrap: true,
            language: "en",
            min_height: 300,
            syntax: "php",
            toolbar: "search, go_to_line, undo, redo, change_smooth_selection, reset_highlight, highlight, word_wrap, help, save, load, new_document, syntax_selection",
            save_callback: "editarea_save"
        });
    });

    $('select[id$="developerChangeItem"]').change(function() {
        var form = $(this).parents('form:first');
        var newFileValue = $(this).val();
        if ($('#viewEditorPreview').length > 0) {
            var iFrameTarget = WEBROOT + '/preview/' + newFileValue;
            $('#viewEditorPreview').attr('src', iFrameTarget);
        }
        form.find('input[id$="currentFile"]').val(newFileValue);
        form.find('input[id$="changeFile"]').val(1);
        form.submit();
    });
}

function url_to_filepath(input) {
    input = str_replace('-sl-', '/', input);
    input = str_replace('-asl-', '\\', input);
    input = str_replace('-dot-', '.', input);
    input = str_replace('-dbdot-', ':', input);
    return input;
}

function date_picker() {
    $.datepicker.setDefaults($.datepicker.regional['fr']);
    each($('.jq_datepicker'), function(datePicker) {
        live($(datePicker), 'click', function(e) {
            $(datePicker).datepicker({
                showOn: 'focus'
            }).focus();
            return false;
        });
    });

}

function image_bank_loading() {
    live($('.image-bank-loader'), 'click', function($this) {
        var id = $this.attr('data-dialog-id');
        $('#' + id).dialog({
            width: 700,
            buttons: {
                Annuler: function() {
                    $(this).dialog("close");
                    return false;
                }
            }
        });
    });

    click($('.image-picker-element img'), function($this) {
        var $parent = $('#' + $this.attr('data-parent'));
        $parent.find('.filenamezone').html($this.attr('data-real-src'));
        $parent.find('.mini-img').attr("src", $this.attr('src'));
        $parent.find('input[type="hidden"]').val($this.attr('data-real-src'));
        var dialogId = $parent.find('.image-bank-loader').attr('data-dialog-id');
        $('#' + dialogId).dialog('close');
    });

    click($('span.delete_image_bank'), function($this) {
        var $image = $this.parents('.image-picker-element:first').find('img');
        var $parentElement = $this.parents('.image-picker-element:first');
        var $parent = $('#' + $image.attr('data-parent'));
        post_array = {};
        post_array['delete_src'] = $image.attr('data-real-src');
        ajax(WEBROOT + '/getdata/delete_img', post_array, function() {
            $parentElement.remove();
        });
    });
}
function delete_image_js() {
    click($('span[id^="delete_img_"]'), function($this) {
        var linkId = $this.attr('id');
        var htmlName = $this.attr('rel');
        var htmlId = '#wrapper_file_' + linkId.replace("delete_img_", "");
        $(htmlId).find('div[class="filenamezone"]').html('');
        $(htmlId + ' img').remove();
        $(htmlId).find('input[name="' + htmlName + '"]').val('');
    });

}


function loadWysiwyg() {
    var $wysiwygEditor = $('textarea[class="wysiwyg_editor"]');
    each($wysiwygEditor, function($textarea) {
        var editor = $textarea.cleditor()[0];
        editor.disable(true);
        editor.disable(false);
        editor.refresh();

    });
}

function limitTextArea(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
}

function resize_now() {
    var contentDiv = $('div[id^="EDIT_IN_PLACE"]').find('div[class*="-dialog_content"]:first');

    var windowHeight = $(window).height();
    var contentHeight = contentDiv.height();

    if (contentDiv.height() > (windowHeight - 140) || contentDiv.css('overflow-y') == 'scroll') {
        contentDiv.css('height', (windowHeight - 150) + 'px').css('overflow-y', 'scroll').css('overflow-x', 'hidden');
        contentDiv.css('top', (contentHeight - (windowHeight - 100)) / 2 + 'px');
    }
    popup_dimensions();
}

function resize_edit_in_place() {
    if ($('div[id^="EDIT_IN_PLACE"]').length > 0) {
        $(window).resize(function() {
            resize_now();
        });
        resize_now();
    }
}
function hover_for_editable_object() {

    $('.hover-for-editable-object').mouseenter(function() {
        $selectedElement = $('#erra-admin-hover-' + $(this).attr('data-object_id'));
        if ($selectedElement.length) {
            $selectedElement.addClass('erra-form-common-hover_selected_content');
            $selectedElement.find('div, ul, li, span, p, table').addClass('erra-form-common-hover_selected_content');
        }
    });

    $('.hover-for-editable-object').mouseleave(function() {
        $selectedElement = $('#erra-admin-hover-' + $(this).attr('data-object_id'));
        if ($selectedElement.length) {
            $selectedElement.removeClass('erra-form-common-hover_selected_content');
            $selectedElement.find('div, ul, li, span, p, table').removeClass('erra-form-common-hover_selected_content');
        }
    });
}

function edit_in_place_buttons() {
    each($('div[id^="EDIT_IN_PLACE"]').find('.erra-form-common-close_button'), function($this) {
        click($this, function($thisElement) {
            $('div[id^="editable_in_place"]').removeClass('launch_edit_in_place');
            closePopup($thisElement, false);
            // FIXME : This is only for mysimplyagenda
            close_slot();
        });
    });

    each($('.erra-form-common-close_button'), function($closeButton) {
        if ($closeButton.parents('.erra-form-common-popup_layer:first').length > 0) {
            $closeButton.show();
        }
    });

    $('div[id^="editable_in_place"]').mouseenter(function() {
        $(this).addClass('erra-form-common-hover_selected');
        $(this).find('div, ul, li, span, p, table').addClass('erra-form-common-hover_selected');
        $(this).css('cursor', 'pointer');
    });

    $('div[id^="editable_in_place"]:not(.manual_editable_in_place)').click(function() {
        var editForm = $(this).find('form[action*="Erra_System_Action/"]');
        editForm.submit();
    });

    $('div[id^="editable_in_place"]').mouseleave(function() {
        $(this).removeClass('erra-form-common-hover_selected');
        $(this).find('div, ul, li, span, p, table').removeClass('erra-form-common-hover_selected');
        $(this).css('cursor', '');
    });

}


function load_modals() {
    $('.pointer').live('mouseenter', function() {
        $(this).css('cursor', 'pointer');
    });
    $('.pointer').live('mouseleave', function() {
        $(this).css('cursor', '');
    });

    click($('div[id^="openDeleteConfirm_"], a[id^="openDeleteConfirm_"]'), function($this) {
        var id = $this.attr('id');
        id = id.replace('openDeleteConfirm_', 'dialogDeleteConfirm_');
        if (JQUERYUI_ENABLED == 1) {
            var dataObject = $this.parents('div[id^="FIELD_LIST_"]:first').attr('data-object');
            ajax(WEBROOT + '/getdata/check_conflicts', {
                'data_object': dataObject, 
                'element_id': id
            }, function(data) {
                if (data.length && data == 'FORBIDDEN') {
                    $('#' + id).html("L'élement sélectionné ne peut pas être supprimé");
                    $('#' + id).dialog({
                        modal: true,
                        buttons: {
                            "Fermer": function() {
                                $(this).dialog("close");
                            }
                        }
                    });
                } else {
                    if (data.length) {
                        $('#' + id).html(data);
                    }
                    $('#' + id).dialog({
                        modal: true,
                        buttons: {
                            "Supprimer": function() {
                                var $form = $this.parents('form:first').submit();
                                $form.submit();
                                $(this).dialog("close");
                            },
                            "Annuler": function() {
                                $(this).dialog("close");
                            }
                        }
                    });
                }

            });
            $('#' + id).dialog('option', 'position', 'center');
        } else {
            // Native UI code
            var formStr = $this.attr('title');
            var parentForm = $this.parents('form:first');
            var answer = confirm(formStr)
            if (answer) {
                parentForm.submit();
            }
        }
    });
}


function cancel_autoscroll_to_top() {
    $('a[href="#"]').click(function(event) {
        event.preventDefault();
        return false;
    });
}


function display_post_messages() {
    var message_width_max_ratio = 0.7;
    $('div[id^="FIELD_"]').find('span[id^="FIELDMESSAGE_"]').each(function() {
        var content = $(this).html();
        if (content.length > 0) {

            if (content.slice(0, 9) == '[success]') {
                create_post_message('success', $(this), message_width_max_ratio);
            } else if (content.slice(0, 7) == '[error]') {
                create_post_message('error', $(this), message_width_max_ratio);
            } else if (content.slice(0, 9) == '[warning]') {
                create_post_message('warning', $(this), message_width_max_ratio);
            } else if (content.slice(0, 6) == '[info]') {
                create_post_message('info', $(this), message_width_max_ratio);
            }
        }
    });
}

function setMessage(element, type, message) {
    if (type == 'success') {
        element.html('<span class="field_message field_message_success">' + message + '</span>').show().delay(5000).fadeOut(500);
    } else if (type == 'info') {
        element.html('<span class="field_message field_message_info">' + message + '</span>').show().delay(5000).fadeOut(500);
    } else if (type == 'warning') {
        element.html('<span class="field_message field_message_warning">' + message + '</span>').show().delay(5000).fadeOut(500);
    } else if (type == 'error') {
        element.html('<span class="field_message field_message_error">' + message + '</span>').show().delay(5000).fadeOut(500);
    }
}

function get_stylized_post_message(type, message) {
    if (type == 'success') {
        return '<span class="field_message field_message_success">' + message + '</span>';
    } else if (type == 'warning') {
        return '<span class="field_message field_message_warning">' + message + '</span>';
    } else if (type == 'error') {
        return '<span class="field_message field_message_error">' + message + '</span>';
    }
    return '<span class="field_message field_message_info">' + message + '</span>';
}

function create_post_message(type, element, message_width_max_ratio) {
    var content = element.html();
    var successMsg = content.slice((type.length + 2), content.length);
    var parentWidth = element.parent().width();
    var contentWidth = element.width();
    var successHtml = get_stylized_post_message(type, successMsg);
    // fit content to message width
    (contentWidth > parentWidth * message_width_max_ratio) ? messageWidth = (parentWidth * message_width_max_ratio) : messageWidth = contentWidth;
    element.html(successHtml);
    element.find('div').width(contentWidth);

}

function load_admin_interface() {
    // Build inner accordions first
    $('div[id^="FIELD_"]').each(function() {
        $(this).find('div[id^="divAccordion_"]').each(function() {
            var activeTab = jQuery.cookie($(this).attr('id'));

            if (activeTab === undefined) {
                activeTab = 0;
            }
            $(this).accordion('destroy');
            $(this).accordion({
                active: parseInt(activeTab),
                autoHeight: false,
                clearStyle: true,
                change: function(event, ui) {
                    var index = jQuery(this).find('h3').index(ui.newHeader[0]);
                    if (index > -1) {
                        jQuery.cookie($(this).attr('id'), index)
                    }
                }
            });
        });
    });
}


function adminbar_enable_ajaxmode() {
    // Switch to ajax mode
    $('.erra-std-adminbar-page_properties').hide();
    //$('.erra-std-adminbar-object_properties').hide();
    $('.erra-std-adminbar-toggle_regions').hide();
    $('.erra-std-adminbar-not_ajax').show();
}

function adminbar_disable_ajaxmode() {
    if ($('.erra-std-adminbar-not_ajax').length) {
        $('.erra-std-adminbar-not_ajax').hide();
    }
    $('.erra-std-adminbar-toggle_regions').show();
}


function disable_ajax_navigation(element) {
    var std_url = window.location.href;
    var newUrl = std_url.replace('/#!', '');
    window.location.href = newUrl;
}
/**
 *Callback
 */
function toggle_region_view(element) {
    $('.erra-region').each(function() {
        var $currentRegion = $(this);
        if ($currentRegion.find('.erra-std-region_name') == undefined || !$currentRegion.find('.erra-std-region_name').length) {
            var randomColor = get_random_color();
            $currentRegion.prepend('<div style="border:2px dotted ' + randomColor + ';" class="erra-std-region_name">Region `' + $currentRegion.attr('id') + '` = ' + $currentRegion.attr('data-view') + '.phtml</div>');
            $currentRegion.css('border', '2px solid ' + randomColor);
        } else {
            $currentRegion.find('.erra-std-region_name').remove();
            $currentRegion.css('border', '');
        }
    })
}


function get_random_color() {
    var letters = '0123456789ABCDEF'.split('');
    var color = '#';
    for (var i = 0; i < 6; i++) {
        color += letters[Math.round(Math.random() * 15)];
    }
    return color;
}

function notification_jqueryui(message) {
    $('#notification').html(message);
    $("#notification").dialog({
        width: 300,
        modal: false,
        buttons: {
            "OK": function() {
                $('#notification').dialog('close');
            }
        }
    });
}

function alert_jqueryui_ok(message, extraFunction) {
    $("#message").dialog({
        autoOpen: false,
        width: 300,
        modal: true,
        position: 'center',
        buttons: {
            "OK": function() {
                extraFunction();
            },
            "Annuler": function() {
                $(this).dialog("close");
            }
        }
    });
    $("#message").html(message);
    $("#message").dialog('open');
}
function alert_jqueryui_modal($element, confirmStr, cancelStr, exec) {
    var dialog_buttons = {};
    if (JQUERYUI_ENABLED == 1) {
        dialog_buttons[confirmStr] = function() {
            exec();
        }
        dialog_buttons[cancelStr] = function() {
            $element.dialog('close');
            $element.dialog('destroy');
        }
        $element.dialog({
            buttons: dialog_buttons,
            modal: true
        });
        $element.dialog('option', 'position', 'center');
        if ($element.attr('width')) {
            $element.dialog('option', 'width', $element.attr('width'));
        }
        if ($element.attr('height')) {
            $element.dialog('option', 'height', $element.attr('height'));
        }
    } else {
        alert('jQueryUI is not enabled');
    }
}

function alert_jqueryui($element, confirmStr, cancelStr, exec) {
    var dialog_buttons = {};
    if (JQUERYUI_ENABLED == 1) {
        dialog_buttons[confirmStr] = function() {
            exec();
        }
        dialog_buttons[cancelStr] = function() {
            $element.dialog('close');
            $element.dialog('destroy');
        }
        $element.dialog({
            buttons: dialog_buttons
        });
        $element.dialog('option', 'position', 'center');
    } else {
        alert('jQueryUI is not enabled');
    }
}

function alert_jqueryui_($element, confirmStr, confirm2Str, cancelStr, exec, exec2) {
    var dialog_buttons = {};
    if (JQUERYUI_ENABLED == 1) {
        dialog_buttons[confirmStr] = function() {
            exec();
            $element.dialog('close');
        }
        dialog_buttons[confirm2Str] = function() {
            exec2();
            $element.dialog('close');
        }
        dialog_buttons[cancelStr] = function() {
            $element.dialog('close');
            $element.dialog('destroy');
        }
        $element.dialog({
            buttons: dialog_buttons
        });
        $element.dialog('option', 'position', 'center');
    } else {
        alert('jQueryUI is not enabled');
    }
}

function alert_jqueryui__($element, confirmStr, confirm2Str, confirm3Str, cancelStr, exec, exec2, exec3) {
    var dialog_buttons = {};
    if (JQUERYUI_ENABLED == 1) {
        dialog_buttons[confirmStr] = function() {
            exec();
            $element.dialog('close');
        }
        dialog_buttons[confirm2Str] = function() {
            exec2();
            $element.dialog('close');
        }
        dialog_buttons[confirm3Str] = function() {
            exec3();
            $element.dialog('close');
        }
        dialog_buttons[cancelStr] = function() {
            $element.dialog('close');
            $element.dialog('destroy');
        }
        $element.dialog({
            buttons: dialog_buttons
        });
        $element.dialog('option', 'position', 'center');
    } else {
        alert('jQueryUI is not enabled');
    }
}
